package com.its.service.impl;

import com.its.pojo.User;
import com.its.service.LoginService;
import com.its.util.Result;
import io.lettuce.core.support.caching.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
 * @author 朱厚强
 * @version 1.0
 * @classname a
 */
@Service
public class LoginServiceImpl implements LoginService {



//    @Autowired
//    private AuthenticationManager authenticationManager;
//
//    @Autowired
//    private RedisCache redisCache;
//
//    @Override
//    public Result login(User user) {
//        UsernamePasswordAuthenticationToken authentication =
//                new UsernamePasswordAuthenticationToken(user.getUserName(), user.getPassword());
//
//
//        Authentication authenticate = authenticationManager.authenticate(authentication);
//
//        if (Objects.isNull(authenticate)) {
//            throw new RuntimeException("登录失败");
//        }
//
//        //使用UUID 作为存入Redis的key，防止用户退出后，旧的token还可以继续使用
//
//        String uuid = UUID.randomUUID().toString();
//
//        String jwt = JwtUtil.createJWT(uuid);
//        Map<String, String> map = new HashMap<>();
//        map.put("token", jwt);
//
//        redisCache.setCacheObject(uuid, authenticate.getPrincipal());
//
//        return new Result(200, "登录成功", map);
//    }
}

